﻿@model IEnumerable<QuanLyGiaoVuUI.Models.ChiTietThongBao.ChiTietThongBaoViewModel>

@{
    ViewBag.Title = "ThongBaoGiaoVu";
    Layout = "~/Views/Shared/_blueWhaleLayout.cshtml";
}
@*<style>
    table.display tbody tr th {
background: bisque;
}
    table.display th {
padding: 5px;
border: 1px solid;
}
    table.display td {
padding-left: 5px;
border: 1px solid;
}
</style>*@

@{ Html.RenderPartial("ThongBaoMenuPartial");}
<div id="main" class="grid_10 gvclientmain">
    <!--  start page-heading -->

    <div id="page-heading" class="box round first grid">
        <h2>Hòm thông báo</h2>
        <!-- end page-heading -->
        <div id="gvclientmaincontent" class="block">
            @if (Model != null && Model.Count() > 0)
            {
                var count=1;
                <table class="data display datatable">
                    <tr>
                        <th class="sorting"><input type="checkbox" id="checkall" />#</th>
                        <th class="sorting">Thông báo</th>
                        <th class="sorting">Người gửi</th>
                        <th class="sorting">Ngày gửi</th>
                        @*<th class="sorting">Xóa</th>*@
                    </tr>

                    @foreach (var chitiet in Model)
                    {
                        <tr id="@chitiet.MaThongBao" class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                            <td class="odd gradeX">
                                <input type="checkbox" class="checkbox" value="@chitiet.MaChiTietThongBao"/></td>
                            @if (chitiet.DaXem == 0)
                            {
                                <td class="odd gradeX" style="font-weight: bold;"><a href="/ThongBao/ChiTietThongBaoGiaoVu/@chitiet.MaThongBao?mct=@chitiet.MaChiTietThongBao">@chitiet.ThongBao.TieuDeThongBao</a></td>
                            }
                            else
                            {
                                <td class="odd gradeX"><a href="/ThongBao/ChiTietThongBaoGiaoVu/@chitiet.MaThongBao?mct=@chitiet.MaChiTietThongBao">@chitiet.ThongBao.TieuDeThongBao</a></td>
                            }
                            <td class="odd gradeX">@(chitiet.ThongBao.NguoiGui != null ? (chitiet.ThongBao.NguoiGui.HoTenGV + "(" + chitiet.ThongBao.NguoiGui.Email + ")") : String.Empty)</td>
                            <td class="odd gradeX">@chitiet.ThongBao.NgayGuiThongBao</td>
                            @*<td class="odd gradeX"><a class="xoaThongBao" rel="@chitiet.MaThongBao" href="#">[X]</a></td>*@
                        </tr>
                    }

                </table>
                <div><input type="button" id="deleteAll" value="Xoá" /></div>
            }
            else
            {
                <div style="margin: 20px; font-size: 20px; color: gray; font-style: italic;">
                    Hòm thông báo rỗng!
                </div>
            }            
        </div>
    </div>
</div>

<div class="clear">&nbsp;</div>

<script>
    $(document).ready(function () {
        $('.xoaThongBao').click(function () {
            var r = confirm("Bạn muốn xóa thông báo này?");
            if (r == true) {
                var mathongbao = $(this).attr("rel");
                $.post("/ThongBao/DeleteThongBaoGiaoVu", { id: mathongbao }, function (data) {
                    if (data.success == true) {
                        $('#' + mathongbao).remove();
                    }
                });
            }
        });
        $('#checkall').change(function () {
            var value = $(this).attr('checked');
            //alert(value);
            if (value == "checked") {
                $(".checkbox").each(function () {
                    $(this).attr("checked", "checked");
                });
            }
            else {
                $(".checkbox").each(function () {
                    $(this).removeAttr("checked");
                });
            }
        });
        $('#deleteAll').click(function () {
            var r = confirm("Bạn muốn xóa những thông báo này?");
            if (r == true) {
                var listID = "";
                $(".checkbox").each(function () {
                    var status = $(this).attr("checked");
                    if (status == "checked") {
                        listID += $(this).attr("value") + ",";
                    }
                });
                //alert(listID);
                $.post("/ThongBao/DeleteThongBaoGiaoVu", { listID: listID }, function (data) {
                    window.location = "/ThongBao/ThongBaoGiaoVu";
                });
                //alert(listID);
            }
        });
    });
</script>

